﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using xiaodingmarket_Domain.Commands;
using xiaodingmarket_Domain.Events.Order;
using xiaodingmarket_Domain_core.Bus;

namespace xiaodingmarket_Domain.EventHandlers
{
    public class OrderEventHandler :
         INotificationHandler<OrderCreatEvent>,
         INotificationHandler<OrderRemoveEvent>,
         INotificationHandler<OrderUpdateEvent>
    {
        private readonly IMediatorHandler Bus;
        public OrderEventHandler(IMediatorHandler bus)
        {

            Bus = bus;
        }
        public Task Handle(OrderCreatEvent notification, CancellationToken cancellationToken)
        {
            Bus.SendCommand(new UpdateCommodityCommand()
            {
                CommodityId = notification.Productid,
                State = Models.EunmType.Commoditystate.onsale

            }) ;
            return Task.CompletedTask;
        }

        public Task Handle(OrderRemoveEvent notification, CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }

        public Task Handle(OrderUpdateEvent notification, CancellationToken cancellationToken)
        {
            throw new NotImplementedException();
        }
    }
}
